package genedit.controller.interfaceActions;

import genedit.controller.SelectionState;
import genedit.model.Workspace;
import genedit.view.graph.GraphDocumentView;
import genedit.view.graph.GraphWorkArea;

import java.awt.Cursor;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;

import javax.swing.AbstractAction;
import javax.swing.ImageIcon;
import javax.swing.KeyStroke;

/**
 * Akcija zadužena za postavljanje aktivnog stanja na stanje selekcije.
 * 
 * @author Nikola
 * 
 */
public class GSelectA extends AbstractAction {
	private static final long serialVersionUID = 1L;

	private static GSelectA instance = null;

	public GSelectA() {
		putValue(NAME, "");
		putValue(SMALL_ICON, new ImageIcon("resources/icons/layer_select.png"));
		putValue(MNEMONIC_KEY, KeyEvent.VK_L);
		putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_L, ActionEvent.CTRL_MASK));
		putValue(SHORT_DESCRIPTION, "Select (Ctrl+L)");
	}

	public static AbstractAction getInstance() {
		if (instance == null)
			instance = new GSelectA();
		return instance;
	}

	/**
	 * Akcija postavlja globalno aktivno stanje na stanje selekcije.
	 */
	public void actionPerformed(ActionEvent event) {
		Workspace.getInstance().setActiveState(new SelectionState(null));

		Cursor cursor = Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR);
		GraphDocumentView document = Workspace.getInstance().getActiveDocument();
		if (document != null) {
			GraphWorkArea test = ((GraphWorkArea) Workspace.getInstance().getActiveDocument()
					.getWorkArea());

			test.setCursor(cursor);

			((GraphWorkArea) document.getWorkArea()).getController().setCurrentState(
					new SelectionState((GraphWorkArea) Workspace.getInstance().getActiveDocument()
							.getWorkArea()));
		}
	}
}